
#if !SILVERLIGHT

using Qdb.Internal;
using Qdb.Tests.Common.Api;
using QdbUnit;

namespace Qdb.Tests.CLI1.Inside
{
	public class OldQdbAssemblyNameRenamingTestCase : TestWithTempFile
	{
		public void TestAssemblyNameEndingWithQdb()
		{
			AssertNameRead("SomeType, exqdb");
		}

		public void TestSimpleAssemblyName()
		{
			AssertNameRead("SomeType, some assembly");
		}

		public void TestOldQdbAssemblyNames()
		{
			AssertNameRead("desktop, qdb", "desktop, Qdb");
			AssertNameRead("desktop.1, qdb-4.0-net1", "desktop.1, Qdb");
			AssertNameRead("cf1, qdb-4.0-compact1", "cf1, Qdb");
		}

		private void AssertNameRead(string name)
		{
			AssertNameRead(name, name);	
		}

		private void AssertNameRead(string originalName, string newName)
		{
			using (IObjectContainer db = QdbEmbedded.OpenFile(TempFile()))
			{
				LocalObjectContainer localObjectContainer = (LocalObjectContainer) db;
				AssertNameRead(localObjectContainer, originalName, newName);
			}
		}

		private static void AssertNameRead(ObjectContainerBase localObjectContainer, string originalName, string newName)
		{
			byte[] originalBytes = localObjectContainer.StringIO().Write(originalName);
			byte[] updatedClassNameBytes = Platform4.UpdateClassName(originalBytes);
			Assert.AreEqual(newName, localObjectContainer.StringIO().Read(updatedClassNameBytes));
		}
	}
}

#endif